import Cookies from 'js-cookie'
import { Base64 } from 'js-base64';

const TokenKey = 'pacargle'

export function getToken() {
  return Cookies.get(TokenKey);
  // return 'eyJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE2NTQ3NjMxNzksImV4cCI6MTY1NDc3MDM3OSwibWFuZ2VySWQiOjEsIm5pY2tOYW1lIjoi6LaF57qn566h55CG5ZGYIiwicm9sZUlkIjoxLCJyZWZyZXNoQ291bnQiOjAsImxvZ2luTmFtZSI6ImFkbWluIn0.-GBRxMyE5Vrc-QnfyO9p0xd5Ndd9FU2mK8yTSuu1tu8'

}

export function setToken(token) {
  Cookies.set(TokenKey, token);
  let sub=eval('(' + Base64.decode(token.split(".")[1]) + ')');
  console.log("989898989898",sub)
  Cookies.set("NICKNAME",sub.nickName);
  Cookies.set("ROLEID",sub.roleId);
  Cookies.set("MANAGERID",sub.mangerId);
  Cookies.set("ISRECHARGE",sub.isRecharge);
  Cookies.set("ROLECODE",sub.roleCode);
}

export function removeToken() {
  return Cookies.remove(TokenKey);
}

export function getNickName(){
  return Cookies.get("NICKNAME");
}

export function getIsRecharge(){
  return Cookies.get("ISRECHARGE");
}


export function getRoleId(){
  return Cookies.get("ROLEID");
}

export function getManagerId(){
  return Cookies.get("MANAGERID");
}

export function getRoleCode(){
  return Cookies.get("ROLECODE");
}

export function getTestUserName(){
  return 'testuser'
}

 
